<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./../../Template/generalTemplate.xhtml">

            <ui:define name="content">
                <f:view beforePhase="#{invoiceCreationResultManagedBean.initView}"> 
                    <h:form>
                        <div style="position:absolute;top:140px;right:70px;">
                            <h:outputLink id="lnk" value="Print">  
                                <p:printer target="invoiceSheet" />  
                                <p:graphicImage value="/images/document-print.png" style="height:25px; width:25px;" />  
                            </h:outputLink> 
                        </div>
                        <div class="round" style="overflow:auto;height:450px;border:solid #AFAFAF 1px;">
                            <p:panel id="invoiceSheet" header="Invoice" >
                                <div style="padding-left:40px;padding-right:70px;">
                                    <div>
                                        <h:outputText style="color: lightblue;font-size:18px;" value="MerLionFood Invoice Sheet"/>
                                    </div>  
                                    <br />
                                    <table>
                                        <tr>
                                            <td width="150" style="font-weight:bold;">
                                                <h:outputText value="Invoice Issue Company:"/>
                                            </td>
                                            <td width="300">
                                                <h:outputText value="Merlion Food Limited"/>
                                            </td>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="DATE:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.invoice.issuing_date}">
                                                    <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                                </h:outputText>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Street Name:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="25 Lower Kent Ridge Road"/>
                                            </td>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Invoice ID:"/>
                                            </td>
                                            <td>
                                                <h:outputText value ="#{invoiceCreationResultManagedBean.invoice.id}"/>   
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="City:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="Singapore"/>
                                            </td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Post Code:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="119081"/>
                                            </td>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    </table>
                                    <br/>
                                    <table>
                                        <tr>
                                            <td width="150" style="font-weight:bold;">
                                                <h:outputText value="Billing To:"/>
                                            </td>
                                            <td width="300">
                                                <h:outputText value="#{invoiceCreationResultManagedBean.company.name}"/>
                                            </td>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Ship To:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.company.name}"/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Street Name:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.deliveryOrder.billingAddress.streetName}"/>
                                            </td>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Street Name:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.deliveryOrder.shippingAddress.streetName}"/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="City:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.deliveryOrder.billingAddress.city}"/>
                                            </td>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="City:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.deliveryOrder.shippingAddress.city}"/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Post Code:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.deliveryOrder.billingAddress.postCode}"/>
                                            </td>
                                            <td style="font-weight:bold;">
                                                <h:outputText value="Post Code:"/>
                                            </td>
                                            <td>
                                                <h:outputText value="#{invoiceCreationResultManagedBean.deliveryOrder.shippingAddress.postCode}"/>
                                            </td>
                                        </tr>
                                    </table>

                                    <p:dataTable style ="margin-top:20px;" value ="#{invoiceCreationResultManagedBean.formDeliveryOrderList()}" var="o">
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="DeliveryOder Id" />
                                            </f:facet>
                                            <h:outputText value="#{o.id}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">Delivery Date</f:facet>
                                            <h:outputText value="#{o.deliveryDate}">
                                                <f:convertDateTime pattern ="yyyy-MM-dd"/>
                                            </h:outputText>    
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">Delivery Location</f:facet>
                                            <h:outputText value="#{o.shippingAddress.streetName},"/>
                                            <h:outputText value="#{o.shippingAddress.city}"/>
                                        </p:column> 
                                    </p:dataTable>   
                                    <p:dataTable style ="margin-top:10px;"  dynamic="true" value="#{invoiceCreationResultManagedBean.lineItemList}" var="l">
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Proudct" />
                                            </f:facet>
                                            <h:outputText value="#{l.product.productName}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Quantity" />
                                            </f:facet>
                                            <h:outputText value="#{l.quantity}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Original Unit Price" />
                                            </f:facet>
                                            <h:outputText value="#{l.product.basePrice}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Promotional Price" />
                                            </f:facet>
                                            <h:outputText value="#{l.product.promotionPrice}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Discount" />
                                            </f:facet>
                                            <h:outputText value="#{l.discount}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Unit Price" />
                                            </f:facet>
                                            <h:outputText value="#{l.price}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Subtotal" />
                                            </f:facet>
                                            <h:outputText value="#{l.cumAmount}" />
                                        </p:column>  
                                    </p:dataTable> 
                                    <h:panelGrid style="margin-top:20px;" columns="2" cellpadding="5">
                                        <h:outputText value ="Total:" style="font-weight:bold;"/>
                                        <h:outputText value= "#{invoiceCreationResultManagedBean.invoice.amountPayable}"/>    
                                        <h:outputText value ="Paid:" style="font-weight:bold;"/>
                                        <h:outputText value= "#{invoiceCreationResultManagedBean.invoice.amountPaid}"/>  
                                        <h:outputText value="Total Due" style="font-weight:bold;"/>
                                        <h:outputText value= "#{invoiceCreationResultManagedBean.invoice.payment_balance}"/>  
                                    </h:panelGrid>
                                    <h:outputText value="Thanks For Doing Business With Us" style="margin-top:350px;color: darkcyan; font-size:18px;margin-left:280px;"/>
                                </div>
                            </p:panel> 

                        </div>
                        <p:commandButton style="margin-top:15px;margin-left:50px;" value="View Record" action="#{invoiceCreationResultManagedBean.viewRecord}" />


                    </h:form>
                </f:view>   
            </ui:define>

        </ui:composition>

    </body>
</html>
